const path = require('path')
const HTMLWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const resolve = (dir) => {
  return path.resolve(__dirname, '../', dir)
}
module.exports = {
  mode: 'development',
  entry: {
    app: resolve('src/main.js'),
  },
  output: {
    path: resolve('dist'),
    filename: '[name].js'
  },
  plugins: [
    new CleanWebpackPlugin(), // 打包之前先清空 打包目录

    new CopyWebpackPlugin({ // version 6.1.2 // https://www.npmjs.com/package/copy-webpack-plugin
      patterns: [
        {
          from: resolve('public/favicon.ico'),
          to: resolve('dist/')
        } 
      ]
    }),
    // CopyWebpackPlugin 5.1.2版本的写法
    // new CopyWebpackPlugin([
    //   {
    //     from: resolve('public/favicon.ico'),
    //     to: resolve('dist/')
    //   }
    // ]),

    new HTMLWebpackPlugin({
      title: 'hello webpack', 
      filename: 'index.html',
      template: resolve('public/index.html'),
      inject: true,
      minify: {
        collapseWhitespace: true, 
        removeAttributeQuotes: true, 
        removeComments: true
      }
    })
  ]
}